import time

from selenium.webdriver.support.wait import WebDriverWait
from appium.webdriver.common.appiumby import By

from appPage.buy_now import BuyNow
from appPage.enter_homepage import EnterHomePage
from appPage.login import Login
from appPage.place_order import PlaceOrder
from appPage.search import Search
from config import PHONE, PWD, SEARCH_TEXT, MESSAGE
from utils.driver_utils import DriverUtils


class Payment:
    def payment(self, driver):
        # WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "com.tpshop.malls:id/weixin_check")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "com.tpshop.malls:id/pay_btn")).click()
        time.sleep(5)

if __name__ == '__main__':
    # 驱动
    driver_utils = DriverUtils()
    driver = driver_utils.get_driver()
    # 进入首页
    enter = EnterHomePage()
    # 登录
    login = Login()
    # 搜索
    search = Search()
    # 立即购买
    buy = BuyNow()
    # 下单
    order = PlaceOrder()
    # 支付
    payment = Payment()
    enter.enter_homepage(driver)
    login.login(driver, PHONE, PWD)
    search.search(driver, SEARCH_TEXT)
    buy.buy_now(driver)
    order.place_order(driver, MESSAGE)
    payment.payment(driver)
    driver_utils.quit_driver()
